var pageii = null;
var grid = null;
$(function() {

	grid = lyGrid({
		pagId : 'paging',
		l_column : [ {
			colkey : "buyId",
			name : "采购单号"
		}, {
			colkey : "deliverDate",
			name : "退货日期",
			renderData : function(rowindex,data, rowdata, column) {
				return new Date(data).format("yyyy-MM-dd hh:mm:ss");
			}
				
		}, {
			colkey : "departmentId",
			name : "部门"
		}, {
			colkey : "supplierId",
			name : "供应商"
		},{
			colkey : "state",
			name : "状态",
			
		}],
		jsonUrl : rootPath + '/parts/parts_retrun_findByPage.shtml',
		dymCol:true,
		checkbox : true,
		serNumber : false
	});
	$("#details").click("click", function() {
		editAccount();
	});
	$("#addFun").click("click", function() {
		addAccount();
	});
	$("#delFun").click("click", function() {
		delAccount();
	});
	$("#search").click("click", function() {// 绑定查询按扭
		
		var searchParams = $("#searchForm").serializeJson();
		grid.setOptions({
			data : searchParams
		});
	});
	
});
function editAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1 || cbox == "") {
		layer.msg("只能选中一个");
		return;
	}
	pageii = layer.open({
		title : "详情",
		type : 2,
		area : [ "1200px", "100%" ],
		content : rootPath + '/parts/parts_return_details.shtml?buyId=' + cbox
	});
}

function addAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1 || cbox == "") {
		layer.msg("只能选中一个");
		return;
	}
		$.getJSON(rootPath + '/parts/parts_return_seach.shtml','buyId='+ cbox,function(data){
			if (data=="success") {
					layer.alert('验收成功!', function(index) {
						parent.grid.loadData();
		        	parent.layer.close(parent.pageii);
		        	return false;
					});
				} else {
					layer.alert('验收失败！', 3);
				}
		});
}

function delAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择删除项！！");
		return;
	}
	layer.confirm('是否删除？', function(index) {
		var url = rootPath + '/parts/parts_return_del.shtml';
		var s = CommnUtil.ajax(url, {
			ids : cbox.join(",")
		}, "json");
		if (s == "success") {
			layer.msg('删除成功');
			grid.loadData();
		} else {
			layer.msg('删除失败');
		}
	});
}


